<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link type="text/css" rel="stylesheet" href="/webjars/bootstrap/3.3.7/css/bootstrap.css">
    <script type="text/javascript" src="/webjars/jquery/3.4.1/jquery.js"></script>
    <script type="text/javascript" src="/webjars/vue/2.6.10/dist/vue.js"></script>
    <script type="text/javascript" src="/webjars/axios/0.19.0/dist/axios.js"></script>
    <script type="text/javascript" src="/webjars/bootstrap/3.3.7/js/bootstrap.js"></script>
</head>
<body>
<div id="vuebox">
    <form class="form-inline" role="form" style="padding-left: 250px;">
        <div class="form-group" style="padding-left: 20px;">
            <label>申报状态:</label>
            <select class="form-control" v-model="status">
                <option value="0">全部</option>
                <option value="1">已申报</option>
                <option value="2">审核中</option>
                <option value="3">已审核</option>
            </select>
        </div>
        <div class="form-group"  style="padding-left: 20px;">
            <button type="button" class="btn btn-primary" @click="select(1)">查询</button>
        </div>
    </form>
    <table class="table table-bordered container">
        <thead>
        <tr>
            <th>项目编号</th>
            <th>项目名称</th>
            <th>申报开始日期</th>
            <th>申报结束日期</th>
            <th>申报状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="item in projectList.list">
            <td>{{item.id}}</td>
            <td>{{item.projectname}}</td>
            <td>{{item.startdate}}</td>
            <td>{{item.enddate}}</td>
            <td>
            <p v-if="item.status==1">已申报</p>
            <p v-if="item.status==2">审核中</p>
            <p v-if="item.status==3">已审核</p>
            </td>

            <td>
                <p v-if="item.status==1"><a href="#" @click="updateproject(item.id)">审核</a></p>
                <p v-if="item.status==2"><a href="#" @click="updateproject(item.id)">审核</a></p>
                <p v-if="item.status==3"></p>
            </td>
        </tr>
        </tbody>
    </table>

    <div class="text-center">
        <ul class="pagination">
            <li v-show="projectList.hasPreviousPage">
                <a href="#" @click.stop="select(projectList.perPage)">&laquo;</a>
            </li>
            <li :class="{active:projectList.pageNum==i}" v-for="i of projectList.navigatepageNums">
                <a href="#" @click.stop="select(i)">{{i}}</a>
            </li>
            <li v-show="projectList.hasNextPage">
                <a href="#" @click.stop="select(projectList.nextPage)">&raquo;</a>
            </li>
        </ul>
    </div>

    <!--模态框-->
    <div class="modal" id="mymodal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" type="button" @click="hideModal(),clearForm()" >&times;</button>
                    <div class="modal-title">
                    申报项目信息
                    </div>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form">
                        <div class="form-group">
                            <label for="id" class="col-sm-2 control-label">项目编号:</label>
                            <div class="col-sm-10">
                                <input v-model="new_project.id" id="id" readonly type="text" class="form-control" placeholder="请输入图书名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="projectname" class="col-sm-2 control-label">项目名称:</label>
                            <div class="col-sm-10">
                                <input v-model="new_project.projectname" id="projectname" readonly type="text" class="form-control" placeholder="请输入图书名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="startdate" class="col-sm-2 control-label">开始日期:</label>
                            <div class="col-sm-10">
                                <input v-model="new_project.startdate" id="startdate" readonly type="text" class="form-control" placeholder="请输入图书摘要"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="enddate" class="col-sm-2 control-label">结束日期:</label>
                            <div class="col-sm-10">
                                <input v-model="new_project.enddate" id="enddate" readonly type="text" class="form-control" placeholder="请输入上传人">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="status" class="col-sm-2 control-label">申报状态</label>
                            <select name="status" class="form-control" id="status" v-model="new_project.status">
                                <option value="1">已申报</option>
                                <option value="2">未审核</option>
                                <option value="3">已审核</option>
                            </select>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" @click="hideModal(),clearForm()">关闭</button>
                    <button class="btn btn-primary" @click="saveModal()">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    var vm=new Vue({
        el:"#vuebox",
        data:{
            projectList:{},
            status:0,
            pageNum:'',
            saveResult:{},
            new_project:{
                id:'',projectname:'',startdate:'',enddate:'',status:''
            }
        },
        methods: {
            select:function (pageNum) {
                axios({
                    url:"/selectPro",
                    method:"get",
                    params:{status:this.status,pageNum:pageNum}
                }).then(res=>{
                    this.projectList=res.data
                    this.pageNum=pageNum
                })
            },
            showModal:function () {
                $('#mymodal').modal('show');
            },
            hideModal:function () {
                $('#mymodal').modal('hide');
            },
            updateproject:function (id) {
                axios({
                    url:"/selectById",
                    method:"get",
                    params:{id:id}
                }).then(res=>{
                    this.new_project=res.data;
                    this.showModal();
                })
            },
            saveModal:function () {
                axios.post("/update",this.new_project).then(res=>{
                    this.saveResult=res.data
                    if(this.saveResult.result=="success"){
                        alert("审核通过!")
                        this.select(this.pageNum);
                        this.hideModal();
                    }else {
                        alert("审核失败请联系管理员")
                        this.hideModal();
                    }
                })
            }

        },
        mounted(){
            this.select(1);
        }
    })
</script>